package com.wiwf.model.manage.socket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import com.wiwf.model.mapper.admin.dao.SysMsgMapper;
import com.wiwf.model.security.service.SysTokenService;

@Configuration
public class BaseWebSocketHandlers implements WebSocketConfigurer {

	@Autowired
	private SysTokenService tokenService;
	@Autowired
	private SysMsgMapper sysMsgMapper;
	
	@Value("${base.api.ws}")
	private String apiWs;
	
	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
		BaseWebSocketDispatcher dispatcher = new BaseWebSocketDispatcher(tokenService, sysMsgMapper);
		
		WebSocketHandlerRegistration registration = webSocketHandlerRegistry.addHandler(dispatcher, apiWs);
		registration.setAllowedOrigins("*");
	}

}
